#include "vector2D.h"

Vector2D::Vector2D(float x, float y) : x_(x), y_(y) {}
float Vector2D::getx() const { return x_; }
float Vector2D::gety() const { return y_; }
void Vector2D::setx(float x) { x_ = x; }
void Vector2D::sety(float y) { y_ = y; }

float Vector2D::length() {
    return sqrt(x_*x_ + y_*y_);
}

Vector2D Vector2D::operator+(const Vector2D& other) const {
    return Vector2D(x_ + other.x_, y_+other.y_);
}

Vector2D& operator+=(Vector2D& other1, const Vector2D& other2) {
    other1.x_ += other2.x_;
    other1.y_ += other2.y_;
    return other1;
}

Vector2D Vector2D::operator*(const float n) {
    return Vector2D(x_*n, y_*n);
}

Vector2D& Vector2D::operator*=(const float n) {
    x_ *= n;
    y_ *= n;

    return *this;
}

Vector2D Vector2D::operator-(const Vector2D& other) {
    return Vector2D(x_-other.x_, y_-other.y_);
}

Vector2D& operator-=(Vector2D& other1, const Vector2D& other2) {
    other1.x_ -= other2.x_;
    other1.y_ -= other2.y_;

    return other1;
}

Vector2D Vector2D::operator/(const float n) {
    return Vector2D(x_/n, y_/n);
}

Vector2D& Vector2D::operator/=(const float n) {
    x_ /= n;
    y_ /= n;
    return *this;
}

void Vector2D::Normalize() {
    float l = length();
    if (l > 0) {
        (*this) *= 1/l;
    }
}

